//
//  QSVTSignHeaderView.m
//  DigitalEconomy_iOS
//
//  Created by Ding on 2020/4/17.
//  Copyright © 2020 DingC. All rights reserved.
//

#import "QSVTSignHeaderView.h"
@interface QSVTSignHeaderView ()

@end
@implementation QSVTSignHeaderView
- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self configSubView];
        [self addGestureRecognizer];
    }
    return self;
}

- (void)configSubView{
    [self addSubview:self.leftImageView];
    [self addSubview:self.companyTextLabel];
    [self addSubview:self.clearButton];
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(kRealValue(12));
        make.width.height.offset(kRealValue(22));
    }];
    [self.companyTextLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self.leftImageView.mas_right).offset(kRealValue(12));
        make.right.equalTo(self).offset(kRealValue(-60));
    }];
    [_clearButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(- kRealValue(10));
    }];
}

- (UIImageView *)leftImageView{
    if (!_leftImageView) {
        _leftImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"search"]];
    }
    return _leftImageView;
}

- (void)addGestureRecognizer{
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(selectAction:)];
    [self addGestureRecognizer:tap];
}

- (void)selectAction:(UITapGestureRecognizer *)tap{
    NSLog(@"选中");
    if (self.didSelectSearchCompanyBlock) {
        self.didSelectSearchCompanyBlock(self);
    }
}


- (UILabel *)companyTextLabel{
    if (!_companyTextLabel) {
        _companyTextLabel = [UILabel labelWithName:@"选择企业名称进行搜索" font:[UIFont QSFontOfSize14] textColor:[UIColor colorWithHexString:@"#C1BFC2"] textAlignment:NSTextAlignmentLeft];
        _companyTextLabel.numberOfLines = 2;
    }
    return _companyTextLabel;
}

- (UIButton *)clearButton{
    if (!_clearButton){
        _clearButton = [UIButton buttonWithType:UIButtonTypeSystem];
        [_clearButton setTitle:@"清空" forState:UIControlStateNormal];
        _clearButton.titleLabel.font = [UIFont QSFontOfSize14];
        [_clearButton addTarget:self action:@selector(clearAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _clearButton;
}

- (void)clearAction:(UIButton *)sender{
    if (self.didClearButtonBlock) {
        self.didClearButtonBlock(self);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
